import axios from "axios";
export default {
  install: function(Vue) {
    Vue.prototype.imageFile = ["jpg", "jpeg", "png", "bmp"];
    Vue.prototype.updateFile = function(video, callback) {
      const config = {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        }
      };
      axios
        .post(
          "https://callback.stqcm.com/ad1/public/index.php?s=api/index/uploadVideo",
          video,
          config
        )
        .then(res => {
          if (typeof callback === "function") {
            callback(res);
          }
        });
    };
    Vue.prototype.deleteFile = function(video_name, callback) {
      axios
        .post(
          "https://callback.stqcm.com/ad1/public/index.php?s=api/index/deleteFile",
          video_name
        )
        .then(res => {
          if (typeof callback === "function") {
            callback(res);
          }
        });
    };
    Vue.prototype.updateExcel = function(file, callback) {
      const config = {
        headers: {
          "Content-Type": "application/x-www-form-urlencoded"
        }
      };
      axios
        .post(
          "https://callback.stqcm.com/ad1/public/index.php?s=api/upload/upload",
          file,
          config
        )
        .then(res => {
          if (typeof callback === "function") {
            callback(res);
          }
        });
    };
    Vue.prototype.getObjectURL = function(file) {
      let url = null;
      if (window.createObjectURL !== undefined) {
        // basic
        url = window.createObjectURL(file);
      } else if (window.webkitURL !== undefined) {
        // webkit or chrome
        url = window.webkitURL.createObjectURL(file);
      } else if (window.URL !== undefined) {
        // mozilla(firefox)
        url = window.URL.createObjectURL(file);
      }
      return url;
    };
  }
};
